package entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table (name= "facturas")
public class FacturaEntity implements Serializable{

	@Transient
	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue
	private Integer nroFactura;
//	@OneToMany (cascade = CascadeType.ALL)
//	@JoinColumn (name= "nroFactura")
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinTable(name="facturasItemsCartas")
	private List<ItemCartaEntity> itemsFactura = new ArrayList<ItemCartaEntity>();
	
	private String estado;
	private float total;
	private Integer nroapmesa;


	public FacturaEntity() {
	}
	
	
	public Integer getNroFactura() {
		return nroFactura;
	}
	public void setNroFactura(Integer nroFactura) {
		this.nroFactura = nroFactura;
	}
	public List<ItemCartaEntity> getItemsFactura() {
		return itemsFactura;
	}
	public void setItemsFactura(List<ItemCartaEntity> itemsFactura) {
		this.itemsFactura = itemsFactura;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((itemsFactura == null) ? 0 : itemsFactura.hashCode());
		result = prime * result
				+ ((nroFactura == null) ? 0 : nroFactura.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FacturaEntity other = (FacturaEntity) obj;
		if (itemsFactura == null) {
			if (other.itemsFactura != null)
				return false;
		} else if (!itemsFactura.equals(other.itemsFactura))
			return false;
		if (nroFactura == null) {
			if (other.nroFactura != null)
				return false;
		} else if (!nroFactura.equals(other.nroFactura))
			return false;
		return true;
	}


	public void setEstado(String estado) {
		this.estado = estado;
	}


	public String getEstado() {
		return estado;
	}


	public void setTotal(float total) {
		this.total = total;
	}


	public float getTotal() {
		return total;
	}


	public void setNroapmesa(Integer nroapmesa) {
		this.nroapmesa = nroapmesa;
	}


	public Integer getNroapmesa() {
		return nroapmesa;
	}

	
}
